package com.example.andhw01;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	int see;
	int past;
	boolean plus=false;
	
	TextView showTextView;

	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		showTextView=(TextView)findViewById(R.id.showText);
		
		Button btn1=(Button)findViewById(R.id.button1);
		Button btn2=(Button)findViewById(R.id.button2);
		Button btn3=(Button)findViewById(R.id.button3);
		Button btn4=(Button)findViewById(R.id.button4);
		Button btn5=(Button)findViewById(R.id.button5);
		Button btn6=(Button)findViewById(R.id.button6);
		Button btn7=(Button)findViewById(R.id.button7);
		Button btn8=(Button)findViewById(R.id.button8);
		Button btn9=(Button)findViewById(R.id.button9);
		Button btn0=(Button)findViewById(R.id.button0);
		Button btnp=(Button)findViewById(R.id.buttonp);
		Button btne=(Button)findViewById(R.id.buttone);
		
		/*
		public void onClick(View v){
			switch(v.getId()){
			
			}
		}
		*/
		
		btn1.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+1;
				showTextView.setText(Integer.toString(see));
				
				
			}
			
		});
		btn2.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+2;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn3.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+3;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn4.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+4;
				showTextView.setText(Integer.toString(see));
				
				
			}
			
		});
		btn5.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+5;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn6.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+6;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn7.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+7;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn8.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+8;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn9.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see+9;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btn0.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plusfinder();
				see=10*see;
				showTextView.setText(Integer.toString(see));
				
			}
			
		});
		btnp.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				plus=true;
				showTextView.setText("+");
				if(past!=0){
					
					see=past+see;
					past=0;
					
				}
				
			}
			
		});
		
		btne.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(past!=0){
					
					see=past+see;
					past=0;
					
					
				}
				showTextView.setText(Integer.toString(see));
				
				
			}
			
		});
		
		
		
	}
	
	void plusfinder(){
		if(plus==true){
			past=see;
			see=0;
			plus=false;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
